package com.woniu.apartment.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.ShaoxUtil;
import com.woniu.apartment.domain.Comments;
import com.woniu.apartment.service.ICommentsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 评论Controller
 * 
 * @author yy
 * @date 2023-04-03
 */
@RestController
@RequestMapping("/apartment/tbcomments")
@Api("评论管理")
public class CommentsWebController extends BaseController
{
    @Autowired
    private ICommentsService commentsService;

    /**
     * 查询评论列表
     */
    //@PreAuthorize("@ss.hasPermi('apartment:tbcomments:list')")
    @GetMapping("web/listByApartId")
    @ApiOperation("评论分页查询")
    public AjaxResult list(Long apartmentId)
    {
        List<Comments> list = commentsService.selectCommentsByApartId(apartmentId);
        return AjaxResult.success("查询成功",list);
    }

    @GetMapping("web/listByApartIdAndUserId")
    public AjaxResult listByApartIdAndUserId(Long apartmentId)
    {
        Long UserId = ShaoxUtil.getUserDtoId();
        Comments Comments = commentsService.listByApartIdAndUserId(apartmentId,UserId);
        System.out.println(Comments);
        if (Comments==null){
            return AjaxResult.success("查询成功");

        }
        return AjaxResult.success("查询成功",Comments);
    }

    @PostMapping("web/add")
    public AjaxResult add( @RequestBody Comments comments,Long apartmentId)
    {

        commentsService.change(comments,apartmentId);
        return  AjaxResult.success("感谢评论");
    }


}
